package com.dayaokeji.rhythmschoolstudent.client.home

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.dayaokeji.rhythmschoolstudent.R
import com.dayaokeji.rhythmschoolstudent.client.common.base.ActivityTemplateMethod
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.remoteImageUrl
import com.dayaokeji.rhythmschoolstudent.client.home.adapter.FunctionComponentAdapter
import com.dayaokeji.rhythmschoolstudent.client.home.course.CourseTableActivity
import com.dayaokeji.rhythmschoolstudent.client.home.data.HomeComponentData
import com.dayaokeji.rhythmschoolstudent.client.home.data.bean.ComponentBean
import com.dayaokeji.rhythmschoolstudent.client.home.meeting.MeetingActivity
import com.dayaokeji.rhythmschoolstudent.glide.GlideUrlModel
import com.dayaokeji.rhythmschoolstudent.glide.GlideUtils
import com.dayaokeji.rhythmschoolstudent.utils.ToastUtils
import kotlinx.android.synthetic.main.activity_highly_recommented.*

/**
 * 重点推荐
 */
class HighlyRecommentedActivity : BaseActivity() , ActivityTemplateMethod {

    companion object {
        private const val COVER_ID = "cover_id"
        fun navigation(cxt: Context,coverId: String) {
            val intent = Intent(cxt, HighlyRecommentedActivity::class.java)
            intent.putExtra(COVER_ID,coverId)
            cxt.startActivity(intent)
        }
    }


    private lateinit var coverId: String

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_highly_recommented)
        toolbar?.let {
            setSupportActionBar(it)
        }
        init()
    }

    override fun init() {
        coverId = intent.getStringExtra(COVER_ID)
        super.init()
        setOnListener()
    }

    override fun setupView() {
        gvFunctionComponent.adapter = FunctionComponentAdapter(HomeComponentData.getData())
    }

    override fun setupViewData() {
        GlideUtils.with(this,false).load(GlideUrlModel(remoteImageUrl +coverId)).into(ivCover)
    }

    private fun setOnListener() {

        gvFunctionComponent.onItemClickListener = AdapterView.OnItemClickListener{ adapter: AdapterView<*>, view1: View, position: Int, id: Long ->
            val componentBean = adapter.getItemAtPosition(position) as ComponentBean
            val iconResId = componentBean.iconResId
            when (iconResId) {
                R.mipmap.ic_home_course -> {
                    CourseTableActivity.navigation(this@HighlyRecommentedActivity)
                }
                R.mipmap.ic_home_meeting -> {
                    startActivity(Intent(this@HighlyRecommentedActivity, MeetingActivity::class.java))
                }
                else -> {
                    ToastUtils.info("正在紧张开发中...")
                }
            }
        }
    }
}
